package com.groupbuying.provider.controller;

import com.groupbuying.provider.context.FilterContextHandler;
import com.groupbuying.provider.dto.forManage.StoreRoleDO;
import com.groupbuying.provider.service.StoreRoleService;
import com.groupbuying.provider.utils.PageUtils;
import com.groupbuying.provider.utils.Query;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;

/**
 * @author groupbuying
 * 角色管理
 */
@Api("服务商角色管理")
@RequestMapping("/role")
@RestController
public class StoreRoleController {

    @Autowired
    StoreRoleService roleService;

    @GetMapping()
    PageUtils list(@RequestParam Map<String, Object> params) {
        // 加入服务商id
        String providerId = FilterContextHandler.getName();
        params.put("providerId",providerId);
        Query query = new Query(params);
        List<StoreRoleDO> roleDOS = roleService.listLike(query);
        int total = roleService.countLike(query);
        PageUtils pageUtil = new PageUtils(roleDOS, total);
        return pageUtil;
    }

    @GetMapping("/userId/{userId}")
    List<BigInteger> roleIdByUserId(@PathVariable String userId){
        return roleService.roleIdsByUserId(userId);
    }

}
